﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using TFSClient = Microsoft.TeamFoundation.WorkItemTracking.Client;

using LeMigue.Scrum.Iterface.Service;
using LeMigue.Scrum.Iterface.Model;
using LeMigue.Scrum.TfsScrumV1.Utils;

namespace LeMigue.Scrum.TfsScrumV1.Service
{
    public class AreaService : AbstractTfsService, IProjectService
    {

        public IList<Project> List(Team team)
        {
            IList<Project> areas = new List<Project>();

            foreach (TFSClient.Node no in TeamProjeto(team.Id).AreaRootNodes)
            {
                if (no.IsAreaNode)
                {
                    areas.Add(criarArea(no));
                }

            }

            return areas;
        }

        public Project Load(int id)
        {
            throw new NotImplementedException();
        }

        public Project Save(Project item)
        {
            throw new NotImplementedException();
        }



        private Project criarArea(TFSClient.Node no)
        {
            Project area = new Project(no.Id, no.Name);

            if (no.HasChildNodes)
            {
                foreach (TFSClient.Node subno in no.ChildNodes)
                {
                    if (subno.IsAreaNode)
                    {
                        area.AddChild(criarArea(subno));
                    }
                }
            }

            return area;
        }

        internal Project Load(TFSClient.Project projeto, int idNode)
        {
            TFSClient.Node no = projeto.IterationRootNodes.GetNode(idNode);
            Project area = new Project(no.Id, no.Name);

            return area;
        }
        
    }
}
